#include "qlvlcolourdialog.h"
#include "ui_qlvlcolourdialog.h"

QLvlColourDialog::QLvlColourDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QLvlColourDialog)
{
    ui->setupUi(this);
}

QLvlColourDialog::~QLvlColourDialog()
{
    delete ui;
}

void QLvlColourDialog::setColours(unsigned char C1, unsigned char C2)
{
    switch (C1)
    {
        case 0x00: ui->rbt1_00->setChecked(true); break;
        case 0x01: ui->rbt1_01->setChecked(true); break;
        case 0x02: ui->rbt1_02->setChecked(true); break;
        case 0x03: ui->rbt1_03->setChecked(true); break;
        case 0x04: ui->rbt1_04->setChecked(true); break;
        case 0x05: ui->rbt1_05->setChecked(true); break;
        case 0x06: ui->rbt1_06->setChecked(true); break;
        case 0x07: ui->rbt1_07->setChecked(true); break;
        case 0x10: ui->rbt1_10->setChecked(true); break;
        case 0x11: ui->rbt1_11->setChecked(true); break;
        case 0x12: ui->rbt1_12->setChecked(true); break;
        case 0x13: ui->rbt1_13->setChecked(true); break;
        case 0x14: ui->rbt1_14->setChecked(true); break;
        case 0x15: ui->rbt1_15->setChecked(true); break;
        case 0x16: ui->rbt1_16->setChecked(true); break;
        case 0x17: ui->rbt1_17->setChecked(true); break;
    }

    switch (C2)
    {
        case 0x00: ui->rbt2_00->setChecked(true); break;
        case 0x01: ui->rbt2_01->setChecked(true); break;
        case 0x02: ui->rbt2_02->setChecked(true); break;
        case 0x03: ui->rbt2_03->setChecked(true); break;
        case 0x04: ui->rbt2_04->setChecked(true); break;
        case 0x05: ui->rbt2_05->setChecked(true); break;
        case 0x06: ui->rbt2_06->setChecked(true); break;
        case 0x07: ui->rbt2_07->setChecked(true); break;
        case 0x10: ui->rbt2_10->setChecked(true); break;
        case 0x11: ui->rbt2_11->setChecked(true); break;
        case 0x12: ui->rbt2_12->setChecked(true); break;
        case 0x13: ui->rbt2_13->setChecked(true); break;
        case 0x14: ui->rbt2_14->setChecked(true); break;
        case 0x15: ui->rbt2_15->setChecked(true); break;
        case 0x16: ui->rbt2_16->setChecked(true); break;
        case 0x17: ui->rbt2_17->setChecked(true); break;
    }
}

void QLvlColourDialog::on_buttonBox_accepted()
{
    unsigned char C1, C2;

    C1 = 0x00;
    C2 = 0x00;

    if (ui->rbt1_00->isChecked())
        C1 = 0x00;
    else if (ui->rbt1_01->isChecked())
        C1 = 0x01;
    else if (ui->rbt1_02->isChecked())
        C1 = 0x02;
    else if (ui->rbt1_03->isChecked())
        C1 = 0x03;
    else if (ui->rbt1_04->isChecked())
        C1 = 0x04;
    else if (ui->rbt1_05->isChecked())
        C1 = 0x05;
    else if (ui->rbt1_06->isChecked())
        C1 = 0x06;
    else if (ui->rbt1_07->isChecked())
        C1 = 0x07;
    else if (ui->rbt1_10->isChecked())
        C1 = 0x10;
    else if (ui->rbt1_11->isChecked())
        C1 = 0x11;
    else if (ui->rbt1_12->isChecked())
        C1 = 0x12;
    else if (ui->rbt1_13->isChecked())
        C1 = 0x13;
    else if (ui->rbt1_14->isChecked())
        C1 = 0x14;
    else if (ui->rbt1_15->isChecked())
        C1 = 0x15;
    else if (ui->rbt1_16->isChecked())
        C1 = 0x16;
    else if (ui->rbt1_17->isChecked())
        C1 = 0x17;

    if (ui->rbt2_00->isChecked())
        C2 = 0x00;
    else if (ui->rbt2_01->isChecked())
        C2 = 0x01;
    else if (ui->rbt2_02->isChecked())
        C2 = 0x02;
    else if (ui->rbt2_03->isChecked())
        C2 = 0x03;
    else if (ui->rbt2_04->isChecked())
        C2 = 0x04;
    else if (ui->rbt2_05->isChecked())
        C2 = 0x05;
    else if (ui->rbt2_06->isChecked())
        C2 = 0x06;
    else if (ui->rbt2_07->isChecked())
        C2 = 0x07;
    else if (ui->rbt2_10->isChecked())
        C2 = 0x10;
    else if (ui->rbt2_11->isChecked())
        C2 = 0x11;
    else if (ui->rbt2_12->isChecked())
        C2 = 0x12;
    else if (ui->rbt2_13->isChecked())
        C2 = 0x13;
    else if (ui->rbt2_14->isChecked())
        C2 = 0x14;
    else if (ui->rbt2_15->isChecked())
        C2 = 0x15;
    else if (ui->rbt2_16->isChecked())
        C2 = 0x16;
    else if (ui->rbt2_17->isChecked())
        C2 = 0x17;

    setResult((C1 * 0x100 + C2) + 1);
}
